import binascii
import math
import struct
from random import random
#----16转10
import numpy as np

# from ast import literal_eval
# data = "0xff"
# out = literal_eval(data)
# print(out)
# print(int("E2E0BDFE2E00",16))
# print(bin(249454888103424))
# time1 = 1<< 7
# print(time1)
# print(hex(time1))
#
# print(int("80",16))
#
# mpu_temp2 = 3443 + 4000
# mpu_temp3 = int(mpu_temp2 / 9.2773)
# mpu_temp4 = mpu_temp3 << 5
# print(mpu_temp4)
# print(hex(mpu_temp4))
# mpu_xacceleration1 = struct.unpack("I", (int(str("FFFFF5EC"), 16)).to_bytes(4, byteorder='big'))
# mpu_xacceleration2 = struct.unpack("i", (mpu_xacceleration1[0]).to_bytes(4, byteorder='big'))
#
# print(mpu_xacceleration2[0] )
#
# mpu_xacceleration3 = int(math.ceil(mpu_xacceleration2[0] / 915.527))
# mpu_xacceleration4 = mpu_xacceleration3 << 7
# print(int(str("FFFE7951"), 16))
# print(mpu_xacceleration1)
# print(mpu_xacceleration2)
# print(mpu_xacceleration3)
# print(mpu_xacceleration4)
# print(hex(mpu_xacceleration4))
#
#
# print(int("03D831F52171",16))
# print(math.ceil(-1.5))
# print(bin(int("-0728",16)))
# a = -1678035
# b = 915.527
# print(a/b)
# aa= hex(-1832)
# print(aa)
# print(hex(-1832))
# print(-0x728<<7)
#
# data1 = (-234496>>16)&0xFF
# data2= (-234496>>8)&0xFF
# Data3 = -234496&0xFF
# print(hex(data1),hex(data2),hex(Data3))
# print(int("0D7D",16))
# print(float.fromhex('0x3A699D00'))
# #-------- IMU_ACC_X_axis转换到can输出
# b =struct.unpack("I",(0xFFE6652D).to_bytes(4,byteorder = 'big'))
# print(b)
# a =struct.unpack("i",(b[0]).to_bytes(4,byteorder = 'big'))
# c = struct.unpack("I",(str(a)).to_bytes(4,byteorder = 'big'))

# print(a[0])
# # print(c)
# #-------- IMU_ACC_X_axis转换到can输出
# #-----温度保留小数点后六位--
# print('{0:f}'.format(int("0D7A",16)/100))
# #-----温度保留小数点后六位--
#
# print(hex(4222520415302))
#
# b = 915.527
# print(a[0]/b)
# print(hex(1832))
# str1= "2022-12-23 03:41:27.906 log_mcucomm [1421][79e9d190][DEBUG] ProtocolReceiveMcuMsg.cpp(157): [mcucomm] Rcv:[44]( +0: 6A A6 80 5A 3E -  00 24 83 07 34 +10: 0C 17 03 29 1B -  03 87 00 00 15 +20: 75 00 00 00 86 -  00 01 89 15 00 +30: 02 31 CD FF F9 -  11 D7 00 07 51 +40: 0B 0D 0C 07 )"
# bb =str1[str1.rfind('+0:'):str1.rfind('+20:')]
# print(bb)
# print(bb[34:36])
# aa= str1[str1.rfind('+10:'):str1.rfind('+20:')]
#
# aa = aa.split('+10:')
# aa =aa[1]
#
# print(aa)
# print(aa[1:3])
# print(aa[4:6])
# print(aa[7:9])
# print(aa[10:12])
# print(aa[13:15])
# print(aa[19:21])
# print(aa[22:24])





#
# disc = {}
# dic = {"name":3}
# a=[1,2,3,3]
# for i in a:
#     if str(i) in disc:
#         disc[str(i)] = int(disc['3']) + 1
#
#     else:
#         disc[str(i)] = str(i)
# print(disc)
# print(disc['3'])
# #
# a = 1670567723628
# b = 1670567723898
#
# print(b-a)
# import xlwt
# import openpyxl
# book = openpyxl.Workbook()  # 打开一个将写的文件
# sheet = book.create_sheet(index=0)  # 在将写的文件创建sheet
# saveExcel = r"C:\Users\ADAYO-34\PycharmProjects\pythonProject\result\excel表格.xlsx"
# sheet.cell(1, 2).value = "123"
# book.save(saveExcel)
#-----------16进制转换--------------------------
# aa = int("03",16)
# print(aa)
import datetime as datetime
# import os
# root = os.getcwd()
#
# log_path = root +r'\original-logfile' +'\\'
# for root, dirs, files in os.walk(log_path):
#   for file in files:
#       aa = os.path.join(root,file)
#       print (aa)
# print(int("B6",16))
#-----------16进制转换--------------------------
# book = xlwt.Workbook(encoding='utf-8',style_compression=0)
#
# sheet = book.add_sheet('数据对比结果',cell_overwrite_ok=True)
# col = ('差值','原值1','原值2')
# for i in range(0,3):
#         sheet.write(1,i+1,col[i])
# sheet.write(2,1,"10")
# savepath = r'C:\Users\ADAYO-34\PycharmProjects\pythonProject\result\excel表格.xls'
# book.save(savepath)

import datetime
import sys
from turtle import pd

# a= "01"
# b=256
# print(int(a)*b)
# import time
# a1='1970-01-01 08:00:07.061'
#
# aa = time.strptime(a1, "%Y-%m-%d %H:%M:%S.%f")
# print(aa)
#---------时间戳转换-----------------------------
# timestr = '2019-01-14 15:22:18.123'
# timesstr1 = '1970-01-01 08:00:07.061'
# datetime_obj = datetime.strptime(timesstr1, "%Y-%m-%d %H:%M:%S.%f")
# obj_stamp = int(time.mktime(datetime_obj.timetuple()) * 1000.0 + datetime_obj.microsecond / 1000.0)
# print(timesstr1)
#---------时间戳转换-----------------------------
# tre_timeArray = time.localtime(7061/1000)
# tre_otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", tre_timeArray)
# print('tre_otherStyleTime',tre_otherStyleTime)

#---------时间戳转换-----------------------------
#
# cd = datetime.datetime.strptime("1970-01-01 00:00:35.999", "%Y-%m-%d %H:%M:%S.%f")
# ts = (cd-datetime.datetime(1970,1,1,8)).total_seconds()
# print(ts)

# t1 = "2022-04-11 17:15:24.661"
# t2 ="2022-04-11 17:15:24.661 "
# print(t2.rstrip())
# print(t1)
# number = icutimelist.index(str(icutimelist[ii]))
# my_list = ['1', '2', '3', '4', '5']
# print(my_list.index('3'))



# aa ="[1424][967fc190][DEBUG] DataWrapper.cpp(74): imu  1970-01-01 11:07:32.475 (0) => 1671016052475"
# if "1970-01-01"in aa:
#
#     bb = aa[aa.rfind('imu'):aa.rfind('(0) =>')]
# else:
#
#     bb = aa[aa.rfind('imu'):aa.rfind('(52) =>')]
# print(bb)
import pandas as pd
import  time

#
# num = "101110"
# my_date = "1999-01-06 5:5:12.234"
# aa = time.strptime(my_date, "%Y-%m-%d %H:%M:%S.%f")
# aa =time.strftime("%Y-%m-%d %H:%M:%S.%f",aa)
# print(aa)

import time
import pandas as pd
# t = "2017-11-24 1:7:2.232"
# t = pd.to_datetime(t)
#先转换为时间数组,然后转换为其他格式
#
# timeStruct = time.strptime(t, "%Y-%m-%d %H:%M:%S.%f")
#
# strTime = time.strftime("%Y-%m-%d %H:%M:%S.%f", timeStruct)

# print(t)
# aa = "20707073262506"
# day = str(hex(eval(aa)))
# print(day)
# # print("2022-12-19 06:06:15")
# #-------------10进制转十六进制------------------
# val = "1671429975"
# val = hex(int(val))
# interval = val[2:].upper()
# print(interval)
# import os
# path = os.path.dirname(os.path.realpath(sys.executable))
# print(path)

# timeArray= "2022-12-15 03:53:57.123"
# timeArray =timeArray.rstrip()
# timeArray = datetime.daitetme.strptime(timeArray, '%Y-%m-%d %H:%M:%S.%f')
# # timeArray = time.mktime(timeArray)
# print(int(timeArray))

# #-----------------------------------------10进制转换成16进制------------------------------------------------------
# val = hex(int("1672737815"))
# print(val)
# interval = val[2:].upper()
# print(interval)
# aa ="0"+interval[0]+" "+ interval[1:3]+" "+interval[3:5]+" "+interval[5:7]+" "+interval[7:9]+" "+interval[9:11]
# interval = interval[1:3]+" "+interval[3:5]+" "+interval[5:7]+" "+interval[7:9]+" "+interval[9:11]
#
# print(interval)
# # print(aa)


# number =0
# allnumber = 0
# key ={'10': 17632, '11': 4, '270': 1, '350': 1}
#
# for i in key:
#     if int(i) <= 11 :
#         a = key[i] *int(i)
#         number = number+ a
#     if 0< int(i) < 10000:
#         b = key[i] *int(i)
#         allnumber = allnumber+b
# aa = number/ allnumber
# print(aa)




# # # #
#---------------------------------------------------------十进制转换成时间---------------------------------------------------
m=bin(int("3DB41A69E43",16))

print(m) # 二进制
print(m[0:16])
print(m[16:22])
print(m[22:28])
print(m[28:34])
print(m[34:])
print(int(m[0:16], 2))
res_date = pd.to_datetime("1980-01-06") + pd.DateOffset(days=int(m[0:16], 2))
res_date =res_date.strftime('%Y-%m-%d')
print(res_date)
print("时："+str(int(m[16:22], 2)))
print("分："+str(int(m[22:28], 2)))
print("秒："+str(int(m[28:34], 2)))
print("毫秒："+str(int(m[34:], 2)))
# a ="Fb"
# b = int(a,16)
# c =hex(255)
# print(b)
# print(c.replace("0x",""))

# a = "9B9C9D9E9FA0A19C9D9E9FA0A1A29D9E9FA0A1A2A39E9FA0A1A2A3A4"
# print(a[0:2])

#
# list =["2022-12-15 03:53:57.0"]
# mcucomm_time = list[0].rstrip()
# # t1 = datetime.datetime.strptime(mcucomm_time, '%Y-%m-%d %H:%M:%S.%f')
# # print(t1)
# t1 = datetime.datetime.strptime("2022-12-20 06:51:53", '%Y-%m-%d %H:%M:%S')
#
# # t2 = "2022-04-11 17:15:24.650"
# t2 = datetime.datetime.strptime("2022-12-20 06:52:49", '%Y-%m-%d %H:%M:%S')
#   # 微秒除以1000可以得到毫秒
# print(str(int((t2 - t1).microseconds / 1000)))
# import config
# import os
# buy_time = config.global_config.getRaw('keywords', 'ODObegincontinuation')
# print(buy_time)
# print(type(buy_time))

# # 获取项目根路径，内容为当前项目的名字
# rootPath = curPath[:curPath.find('pythonProject') + len('pythonProject')]
# print(rootPath)
# time1 = " 2022-12-16 08:55:49.436 "
# time1 = time1.rstrip()
# print(time1)
# time1 = time1.lstrip()
# print(time1)



# year = int(str(34), 16) + 1970
# month =   int("0C",16)
# day = int("0F",16)
# hour = int("10",16)
# minuet = int("24",16)
# seconds = int("02",16)
# millisecond1 = int("00",16) * 256
# millisecond2 =  int("AE",16)
# milliseconds = int(millisecond1) + int(millisecond2)
# mcutime = str(year) + "-" + str(month) + "-" + str(day) + " " + str(hour) + ":" + str(
#                 minuet) + ":" + str(
#                 seconds) + "." + str(
#                 milliseconds)
# # print(mcutime)
#
#
# aa = ' D4 81 86 34 0D '
# aa = aa.rstrip()
# print(aa)
# aa = aa.lstrip()
# print(aa)
# #

# t1 = datetime.datetime.strptime("2024-11-13 63:63:59.2647", '%Y-%m-%d %H:%M:%S.%f')
# t2 = datetime.datetime.strptime("2024-11-13 63:63:59.2667", '%Y-%m-%d %H:%M:%S.%f')
# bb = (t2 - t1).microseconds/1000
# t1 =  int(time.mktime(t1.timetuple()) * 1000.0 + t1.microsecond / 1000.0)
# t2 = int(time.mktime(t2.timetuple()) * 1000.0 + t2.microsecond / 1000.0)
# aa = int(t2) -int(t1)
#
# #
# print(aa)
# print(bb)



# t2 = "1970-01-01 00:00:37.112"
# t2 = datetime.datetime.strptime(t2, '%Y-%m-%d %H:%M:%S.%f')/1000
# # deltat = (t1 - t2).microseconds/1000  # 微秒除以1000可以得到毫秒
# print(str(t2))
#
# obj_stamp = int(time.mktime(t1.timetuple()) * 1000.0 + t1.microsecond / 1000.0)  #毫秒时间转换成时间戳
# print(aa)

# #------------时间戳转成时间------------------
# time_1 = 1671804925913	    # 以2020/10/5 10:12:56为例子
#
# d = datetime.datetime.fromtimestamp(time_1/1000)
# str1 = d.strftime("%Y-%m-%d %H:%M:%S.%f")
# # str1 = datetime.datetime.strptime(str1, '%Y-%m-%d %H:%M:%S.%f')
# print(str1)

# t2 = "1970-01-01 00:00:37.112"
# t2 = datetime.datetime.strptime(t2, '%Y-%m-%d %H:%M:%S.%f')
# time_array = time.strptime(t2, '%Y-%m-%d %H:%M:%S.%f')
# stamp_tm = int(time.mktime(time_array))
# return_tm = hex(stamp_tm)[2:]
# print(return_tm)

# #十进制转换成二进制再转换成时间
#
aa = int("3DB0AF6F190",16)
receivetime_old = bin(int(4239316744040)) # 十进制字符串转换成二进制

# -------------------------二进制字符串转换成整数并拼接成时间------------------------------------
year = pd.to_datetime("1980-01-06") + pd.DateOffset(days=int(receivetime_old[0:16], 2))
year = year.strftime('%Y-%m-%d')
hour =str(int(receivetime_old[16:22], 2))
minute = str(int(receivetime_old[22:28], 2))
seconds = str(int(receivetime_old[28:34], 2))
milliseconds =  str(int(receivetime_old[34:], 2))
if int(hour) < 10:
    hour = "0" + str(hour)
if int(minute) < 10:
    minute = "0" + str(minute)
if int(seconds) < 10:
    seconds = "0" + str(seconds)
if int(milliseconds) < 10:
    milliseconds = "00" + str(milliseconds)
if 10 <= int(milliseconds) < 100:
    milliseconds = "0" + str(milliseconds)
sf_receivetime = year+ " "+ hour+":"+minute+":"+seconds+"."+milliseconds
print(sf_receivetime)

# t2 = "11:00:37.1120"
# t3 = "11:00:37.1221"
# t2 = datetime.datetime.strptime(t2, '%H:%M:%S.%f')
# t3 = datetime.datetime.strptime(t3, '%H:%M:%S.%f')
# print(int((t3-t2).microseconds/1000))

#--时间戳转时间----------------------------------------------
# ten_timeArray = time.localtime(1672737836)
# ten_otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", ten_timeArray)
# print(ten_otherStyleTime)
#--时间戳转时间----------------------------------------------

#-----获取16进制转换成二进制后末尾是不是1或0以及几位
# a = int("02",16)
#
# a_vail = a & 0x01
# a_len = (a&0x0e) >>1
# print(a_vail,a_len)

#print(bin(int("01",16)))


# a = "2f2a2cCF1D1E1F22"
# print(a[2:16])
#
# import pandas as pd
#
# sites = {1: "Google", 2: "Runoob", 3: "Wiki"}
#
# myvar = pd.Series(sites, index = [1, 2,3])
#
# print(myvar)
#----16进制字符串转换成时间非utc时间------------------

# receivetime_old = int("12D4B18B",16)
# ten_timeArray = time.localtime(receivetime_old)
# ten_otherStyleTime = time.strftime("%H:%M:%S", ten_timeArray)
# print(ten_otherStyleTime)
# print(hex(255))


#---转换成utc时间
# dtime_obj = datetime.datetime.utcfromtimestamp(int("12D4B18B", 16))
# datetime_str = dtime_obj.strftime("%H:%M:%S")
# time2 = dtime_obj + datetime.timedelta(hours=8)
# print(time2)
#
# a = ["aaab","bbb","aaa","www","aaa"]
# number = a.index("aaa")
# print(a.index("aaa"))
# del a[:number]
# print(a)

# mpu_North_vehicle_speed1 = struct.unpack("I", (int(str("FFFFC888"), 16)).to_bytes(4, byteorder='big'))
# mpu_North_vehicle_speed2 = struct.unpack("i", (mpu_North_vehicle_speed1[0]).to_bytes(4, byteorder='big'))
# mpu_East_vehicle_speed3 = int(mpu_North_vehicle_speed2[0] / 1525.9)
# mpu_East_vehicle_Decimal = int(str(mpu_East_vehicle_speed3 << 7).replace("-", ""))
# print(mpu_North_vehicle_speed1,mpu_North_vehicle_speed2,mpu_East_vehicle_speed3,mpu_East_vehicle_Decimal)
# print(bin(16754816))
# print((~22400+1).to_bytes(3, 'big', signed=True))
# oo= 22400
# print(int(str(bin(~oo+1 & 0xFFfffe)),2))
# print(-9<< 7)
# print(bin(~1152+1 & 0xFFfffe))
# print(int("ffa880",16))
#
# mpu_East_vehicle_speed1 = struct.unpack("I", (int(str("FFFF5718"), 16)).to_bytes(4, byteorder='big'))
# mpu_East_vehicle_speed2 = struct.unpack("i", (4294924056).to_bytes(4, byteorder='big'))
# mpu_East_vehicle_speed3 = int(mpu_East_vehicle_speed2[0] / 1525.9)
# mpu_East_vehicle_Decimal = int(str(mpu_East_vehicle_speed3 << 7).replace("-", ""))
#
# print(mpu_East_vehicle_speed2,mpu_East_vehicle_speed3,mpu_East_vehicle_Decimal)
# print(hex(int("0101011100011000",2)))
# print(bin(43240))
# print(int("5718",16)<< 7)
# print(bin(int("ffff5718",16)))
# print(bin(43240))
# print(bin(~43240))
print(int("3D9608259008",16))